#include<bits/stdc++.h>
using namespace std;
#define int long long

int dx[] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dy[] = {0, 1, 1, 1, 0, -1, -1, -1};

int n, m;
char ch[105][105];

void dfs(int x, int y) {
	for (int i = 0; i < 8; i++) {
		int xx = x + dx[i];
		int yy = y + dy[i];

		if (ch[xx][yy] != 'W')
			continue;
		ch[xx][yy] = '.';
		dfs(xx, yy);
	}
}

signed main() {
	cin >> n >> m;
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= m; j++)
			cin >> ch[i][j];

	int ans = 0;
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			if (ch[i][j] == 'W') {
				dfs(i, j);
				ans++;
			}
		}
	}
	cout << ans;
	return 0;
}
